﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// PaperCls业务逻辑的简要说明。
    /// </summary>
    public class PaperCls
    {
        /// <summary>
        /// 组织机构的DAL
        /// </summary>
        private readonly DAL.PaperCls dal = new DAL.PaperCls();
        /// <summary>
        /// 构造函数
        /// </summary>
        public PaperCls()
        { }

        /// <summary>
        /// 是否存在该记录
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="fPaperClsNo">管理编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string fPaperClsNo, string fEntityNo)
        {
            return dal.Exists(fPaperClsNo, fEntityNo);
        }


        /// <summary>
        /// 删除一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="fPaperClsNo">管理编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>是否存在</returns>
        public bool Delete(string fPaperClsNo, string fEntityNo)
        {

            return dal.Delete(fPaperClsNo, fEntityNo);
        }
        /// <summary>
        /// 增加一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
       /// <param name="model">对象</param>
       /// <returns>添加的对象</returns>
        public bool Add(Model.PaperCls model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更像一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="model">对象</param>
        /// <returns>添加的对象</returns>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.PaperCls model)
        {
            return dal.Update(model);
            
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="fPaperClsNo">管理编号</param>
        /// <param name="fEntityNo">公司编号</param>
       /// <returns>具体一个对象</returns>
        public Model.PaperCls GetModel(string fPaperClsNo, string fEntityNo)
        {

            return dal.GetModel(fPaperClsNo, fEntityNo);
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
       /// <param name="strWhere">查询条件</param>
        /// <returns>DataTableToList表</returns>
        public List<Model.PaperCls> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 通过编号得到对象
        /// </summary>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>DataTableToList表</returns>
        public List<Model.PaperCls> GetListByClsNo(string fEntityNo)
        {
            DataSet ds = dal.GetListByClsNo(fEntityNo);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="dt">DataTable表</param>
        /// <returns>List集合</returns>
        public List<Model.PaperCls> DataTableToList(DataTable dt)
        {
            List<Model.PaperCls> modelList = new List<Model.PaperCls>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PaperCls model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PaperCls();
                    if (dt.Rows[n]["FPaperClsNo"] != null && dt.Rows[n]["FPaperClsNo"].ToString() != "")
                    {
                        model.FPaperClsNo = dt.Rows[n]["FPaperClsNo"].ToString();
                    }
                    if (dt.Rows[n]["FPaperClsName"] != null && dt.Rows[n]["FPaperClsName"].ToString() != "")
                    {
                        model.FPaperClsName = dt.Rows[n]["FPaperClsName"].ToString();
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
    }
}
